<%--
  Created by IntelliJ IDEA.
  User: 秋梓
  Date: 2021/12/6
  Time: 11:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%@include file="head.jsp"%><br/><br/>
------------------------ 用户管理 --------------------------
<br/><br/>
<table>
    <c:forEach items="${usersNotAdmin}" var="user">
        <tr>
            <td>&nbsp;UID:${user.getId()}&nbsp;<td/>
            <td>&nbsp;用户名:<input name="username" value="${user.getUsername()}" disabled>&nbsp;<td/>
            <td>&nbsp;口令:<input name="password" value="${user.getPassword()}" disabled>&nbsp;<td/>
            <c:if test="${user.isStop() == false}">
                <td>&nbsp;状态:正常&nbsp;<td/>
                <td><button onclick="editUserStatus(${user.getId()}, false)">
                    禁用
                </button>&nbsp;</td>
            </c:if>
            <c:if test="${user.isStop() == true}">
                <td>&nbsp;状态:已禁用&nbsp;<td/>
                <td>&nbsp;<button onclick="editUserStatus(${user.getId()}, true)">
                    启用
                </button>&nbsp;</td>
            </c:if>
            <td>&nbsp;&nbsp;<button onclick="showCart('${user.getUsername()}')">
                查看此用户的订单信息
            </button></td>
        </tr>
    </c:forEach>
</table>
<br/>
----------------------- 管理员编辑 -------------------------
<br/><br/>
<table>
    <c:forEach items="${usersIsAdmin}" var="user">
        <c:if test="${sessionScope.user.getUsername() != user.getUsername()}">
            <c:if test="${adminIdMap.get(user.getId()) == -1}">
                <tr>
                    <td>&nbsp;UID:${user.getId()}&nbsp;<td/>
                    <td>&nbsp;用户名:<input name="username" value="${user.getUsername()}" disabled>&nbsp;<td/>
                    <td>&nbsp;口令:<input name="password" value="${user.getPassword()}" disabled>&nbsp;<td/>
                    <c:if test="${user.isStop() == false}">
                        <td>&nbsp;状态:正常&nbsp;<td/>
                        <td><button disabled>禁用</button>&nbsp;</td>
                    </c:if>
                    <c:if test="${user.isStop() == true}">
                        <td>&nbsp;状态:已禁用&nbsp;<td/>
                        <td><button disabled>启用</button>&nbsp;</td>
                    </c:if>
                    <td>&nbsp;&nbsp;<button onclick="adminEditStatusChange(${user.getId()}, 1)">
                        编辑
                    </button>&nbsp;</td>
                    <td><button onclick="deleteAdmin(${user.getId()})">
                        删除此管理员
                    </button>&nbsp;</td>
                </tr>
            </c:if>
            <c:if test="${adminIdMap.get(user.getId()) == 1}">
                <tr>
                    <td>&nbsp;UID:${user.getId()}&nbsp;<td/>
                    <form action="editAdminFromUsersServlet" method="post">
                        <input name="userid" value="${user.getId()}" style="display:none;">
                        <td>&nbsp;用户名:<input name="username" value="${user.getUsername()}">&nbsp;<td/>
                        <td>&nbsp;口令:<input name="password" value="${user.getPassword()}">&nbsp;<td/>
                        <button id="inBtn" style="display: none"></button>
                    </form>
                    <c:if test="${user.isStop() == false}">
                        <td>&nbsp;状态:正常&nbsp;<td/>
                        <td><button onclick="editUserStatus(${user.getId()}, false)">
                            禁用
                        </button>&nbsp;</td>
                    </c:if>
                    <c:if test="${user.isStop() == true}">
                        <td>&nbsp;状态:已禁用&nbsp;<td/>
                        <td><button onclick="editUserStatus(${user.getId()}, true)">
                            启用
                        </button>&nbsp;</td>
                    </c:if>
                    <td>&nbsp;&nbsp;<button onclick="adminEditStatusChange(${user.getId()}, -1)">
                        保存
                    </button>&nbsp;</td>
                    <td><button onclick="deleteAdmin(${user.getId()})">
                        删除此管理员
                    </button>&nbsp;</td>
                </tr>
            </c:if>
        </c:if>
    </c:forEach>
</table>
<br/>---------------------------------------------------------------------------------------------<br/>
<form action="addAdminIntoUsersServlet" method="post">
    管理员新增:&nbsp;UID:**&nbsp;
    &nbsp;用户名:<input name="username">&nbsp;
    &nbsp;口令:<input name="password">&nbsp;
    <button>确定</button>
</form>

</body>
</html>

<script>
    function editUserStatus(id) {
        window.location.href = "http://localhost:8080/JavaBookShop/editUserStatusServlet?id="+id;
    }
    function showCart(username) {
        window.location.href = "http://localhost:8080/JavaBookShop/showCartServlet?username="+username;
    }
    function adminEditStatusChange(id, status) {
        window.location.href = "http://localhost:8080/JavaBookShop/adminEditStatusChangeServlet?id="+id+"&status="+status;
        if (status == -1) {
            document.getElementById("inBtn").click();
        }
    }
    function deleteAdmin(id) {
        window.location.href = "http://localhost:8080/JavaBookShop/deleteAdminServlet?id="+id;
    }
</script>